import Cookies from 'js-cookie'

const TokenKey = 'pool-token'

export function setUser(user) {
  Cookies.remove('children_account')
  return Cookies.set(TokenKey, JSON.stringify(user))
}

export function getUser() {
  return Cookies.get(TokenKey)?(JSON.parse(Cookies.get(TokenKey)) || {}):{}
}

export function getToken() {
  return getUser().token
}

export function removeToken() {
  Cookies.remove('children_account')
  return Cookies.remove(TokenKey)
}

// export async function getChildAccount(fun){
//   await pooluser.poollist().then(response=>{
//     if (response.success){
//        for(let bb in response.result){
//          if (parseInt(Cookies.get('children_account')) === response.result[bb]['id']){
//             fun(response.result[bb])
//          }
//        }
//     }
//   })
//   return {}
// }
